package com.itheima.manager;
import com.itheima.domain.SmsHomeNewProduct;
import com.itheima.service.db.SmsHomeNewProductService;
import com.itheima.util.R;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
@Component
public class SmsHomeNewProductManager {

        @DubboReference
        SmsHomeNewProductService smsHomeNewProductService;

        public R addNewProduct(@RequestBody List<SmsHomeNewProduct> newProducts) {
            for (SmsHomeNewProduct newProduct : newProducts) {
                smsHomeNewProductService.save(newProduct);

            }
            return R.success(null);
        }

        public R deleteBrand(List<Long> ids) {
            smsHomeNewProductService.deleteNewProduct(ids);
            return R.success(null);
        }

/*        public R getNewProductByPage(Long pageNum, Long pageSize, String productName, Integer recommendStatus) {
        Page<SmsHomeNewProduct> page = smsHomeNewProductService.getNewProductByPage(pageNum,pageSize,productName,recommendStatus);
            return new PageResult(Long.parseLong(String.valueOf(page.getCurrent())), Long.parseLong(String.valueOf(page.getSize())), Long.parseLong(String.valueOf(page.getTotal())), page.getRecords());
        }*/
        public R findByPage(Integer pageNum, Integer pageSize,String productName,Integer recommendStatus) {
            return R.success(smsHomeNewProductService.findByPage(pageNum, pageSize,productName,recommendStatus));
    }
        public R updateNewProduct(List<Long> ids, Integer recommendStatus) {
            for (Long id : ids) {
                smsHomeNewProductService.updateNewProduct(id,recommendStatus);
            }
            return R.success(null);
        }

        public R updatesortNewProduct(Long id, Integer sort) {
            smsHomeNewProductService.updatesortNewProduct(id,sort);

            return R.success("排序成功");
        }

}
